<template>
  <div>
    <!-- <van-loading size="24px" style="display: none">加载中...</van-loading> -->
    <div class="app_top">
      <div class="top_wrap">
        <h1 class="logo">
          <a href="/find" ><img src="@/assets/images/logo.png">线上地摊</a>
        </h1>
        <router-link to="/find">首页</router-link>
        <router-link to="/collect">收藏栏</router-link>
        <router-link to="/order">我的订单</router-link>
        <router-link to="/my">个人中心</router-link>
        <router-link to="/upload">闲置发布</router-link>
        <router-link to="/cs">客服</router-link>
        <div class="search">
          <input type="text" placeholder="请输入书名" class="input1" />
          <div class="search-icon"></div>
        </div>
        <div class="login_flag" @click="showLoginPage" v-if='loginFlag'>登录</div>
        <div class="login_flag2" v-else><span>{{nowUser.username}}</span>,欢迎您！
          <div class="back" @click="back">退出登录</div>
        </div>
      </div>
    </div>
     <Login></Login>
  </div>
</template>

<script>
import Login from '@/components/Login'
import { mapState, mapMutations } from 'vuex'
export default {
  name: 'TopWrap',
  computed: {
    ...mapState(['loginFlag', 'nowUser'])
    // console.log(this.$store)
  },
  components: {
    Login
  },
  methods: {
    // ...mapMutations(['changeLoginFlag', 'backUserInfo']),
    ...mapMutations(['changeLoginFlag', 'setNowUser']),
    showLoginPage () {
      document.querySelector('.loginbox').style.display = 'block'
    },
    back () {
      this.setNowUser({ username: '', passsword: '' })
      // console.log(this.nowUser)
      this.changeLoginFlag()
    }
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  color: #333;
  font-family: Arial, Helvetica, sans-serif;
}
.app_top {
  position: relative;
  z-index: 1000;
  height: 70px;
  box-sizing: border-box;
  background: #242424;
  border-bottom: 1px solid #000;
}
.top_wrap {
  position: relative;
  width: 1100px;
  height: 100%;
  margin: 0 auto;
}
.top_wrap a {
  float: left;
  height: 70px;
  font-size: 14px;
  padding: 0 19px;
  text-align: center;
  line-height: 70px;
  color: #ccc;
  text-decoration: none;
  /* background-color: dimgray; */
}
.top_wrap .logo a {
  float: left;
  width: 250px;
  height: 100%;
  padding-right: 20px;
  font-weight: normal;
  font-family: serif;
  color: white;
  font-size: 24px;
  /* text-indent: -9999px; */
  /* cursor: pointer; */
}
.top_wrap .logo a:hover {
  background-color: #242424;
}
.top_wrap .logo img {
  height: 55px;
  vertical-align: middle;
}
.top_wrap a.router-link-active,
.top_wrap a:hover {
  color: white;
  background-color: black;
}

.top_wrap a.router-link-active {
  position: relative;
}
/* 小角标 */
.router-link-active::after {
  position: absolute;
  bottom: 0px;
  left: 50%;
  transform: translateX(-50%);
  width: 0px;
  height: 0px;
  /* color: purple; */
  /* background-color: pink; */
  border: 10px solid #f5f5f5;
  border-color: transparent transparent #f5f5f5 transparent;
  content: "";
}
.top_wrap .search {
  position: absolute;
  /* 这里是偏向于向右偏移 */
  right: 150px;
  top: 50%;
  transform: translateY(-50%);
  /* position: absolute;
  top: 0; */
  width: 150px;
  height: 45px;
}
.search input {
  float: left;
  cursor: auto;
  width: 150px;
  height: 28px;
  border: none;
  font-size: 12px;
  /* color: #6d757a; */
  color: #333;
  line-height: 28px;
  padding-left: 15px;
  /* background: #f1f3f5; */
  border-radius: 25px;
  margin-top: 9px;
  outline: none;
}
.search .search-icon {
  float: left;
  width: 20px;
  height: 20px;
  margin: 25px 0px 0px -30px;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  cursor: pointer;
  transform: translateY(-50%);
  background-image: url(@/assets/images/搜索.png);
}
.login_flag,.login_flag2 {
  position: absolute;
  top: 50%;
  left: 90%;
  transform: translateY(-50%);
  text-align: left;
  width: 120px;
  height: 70px;
  font-size: 12px;
  line-height: 70px;
  /* background-color: pink; */
  color: #ccc;
  cursor: pointer;
  /* overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical; */
}
.login_flag2 span {
  float: left;
  text-align: left;
  width: 40px;
  height: 70px;
  font-size: 12px;
  line-height: 70px;
  /* background-color: blue; */
  color: #ccc;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.back {
  display: none;
}
.login_flag2:hover .back{
 display: block;
 position: absolute;
 /* top: 100%; */
 left: -20%;
 transform: translateY(-130%);
 text-align: center;
 text-decoration: underline;
 width: 120px;
 height: 45px;
 font-size: 12px;
 line-height: 45px;
 color: #78786a;
 cursor: pointer;
 background-color: #242424;
 z-index: 999;
}

.login_flag:hover{
  color: #78786a;
  text-decoration:underline;
}
</style>
